﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string sql = "select * from StudentInfo" +
                " where stu_name = @name and password = @pwd";

            SqlParameter[] p =
            {
                new SqlParameter("@name",TbxUserName.Text),
                new SqlParameter("@pwd",TbxPassword.Text),
            };
            SqlDataReader sdr = SqlHelper.ExcuteReader(sql, p);
            if (sdr.Read())
            {
                Session["CurrentUserName"] = TbxUserName.Text;
                Literal1.Text = "登录成功";
                Response.Redirect("Home.aspx");
            }
            else
            {
                Literal1.Text = "用户名或密码错误";
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("WebForm1.aspx");
        }
    }
}